<template>
	<view>
		<view class="ZheZhao" v-if="types" @click="changeTypesEvent" @touchmove.prevent></view>
		<view class="DiaLogShai" v-if="types">
			<view class="DiaLogShais">
				<view class="DiaLogShaisFaBu">
					<view class="DiaLogTitle">发布日期</view>
					<view class="example-body">
						<uni-datetime-picker v-model="this.timeRange" type="daterange" />
					</view>
				</view>
				<view class="DiaLogShaisFenLei">
					<view class="DiaLogTitle">行业分类</view>
					<view class="DiaLogShaiList">
						<view v-for="(item, index) in industryType" :key="index"
							:class="['DiaLogShaiLi', activeTabsIndex === index ? 'on' : '']"
							@click="changeSelect(item, index)">{{ item.label }}</view>
					</view>
				</view>
			</view>
			<view class="DiaLogShaix">
				<view class="DiaLogShaiReset" @click="clear">重置</view>
				<view class="DiaLogShaiSubmit" @click="changeTypesEvent">确认</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { useStore } from 'vuex';
	import { DICT_TYPES } from '@/store/modules/dict';

	export default {
		props: {
			types: Boolean,
		},

		data() {
			return {
				industryType: [],
				activeTabsIndex: -1,

				industryTypeValue: -1,
				timeRange: [],
			};
		},
		methods: {
			changeTypesEvent() {
				this.$emit("changeTypes", this.industryTypeValue, this.timeRange);
			},

			clear() {
				this.activeTabsIndex = -1;
				this.industryTypeValue = -1;
				this.timeRange = [];
			},

			changeSelect(item, index) {
				this.activeTabsIndex = index;
				this.industryTypeValue = item.value;
			},

			// 查询字典数据
			async getDictData() {
				const store = useStore();
				// 从Vuex中获取行业分类字典
				this.industryType = await store.dispatch('dict/loadDict', DICT_TYPES.INDUSTRY_TYPE);
			},
		},
		mounted() {
			this.getDictData();
		},
	};
</script>

<style lang="scss">
	.ZheZhao {
		overflow: hidden;
		position: fixed;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;
		z-index: 98;
		background: rgba(0, 0, 0, 0.5);
	}

	.DiaLogShai {
		position: fixed;
		right: 0;
		top: 0;
		width: 660rpx;
		height: 100%;
		box-sizing: border-box;
		background: #f7f8fc;
		z-index: 99;
		border-radius: 30rpx 0 0 0;

		.DiaLogShais {
			height: calc(100% - 160rpx);
			overflow-y: auto;

			.DiaLogShaisFaBu {
				padding: 0 40rpx 40rpx;
				margin-bottom: 30rpx;
				border-radius: 30rpx;
				background: #ffffff;
			}

			.DiaLogTitle {
				height: 86rpx;
				line-height: 86rpx;
				padding: 10rpx 0 0;
				font-size: 28rpx;
				color: #202020;
			}

			.DiaLogShaisFenLei {
				padding: 0 40rpx 20rpx;
				margin-bottom: 30rpx;
				border-radius: 30rpx;
				background: #ffffff;

				.DiaLogShaiList {
					overflow: hidden;

					.DiaLogShaiLi {
						float: left;
						height: 50rpx;
						line-height: 50rpx;
						padding: 0 11rpx;
						background: #f9f9f9;
						border: 2rpx solid #f9f9f9;
						border-radius: 10rpx;
						margin-right: 20rpx;
						margin-bottom: 20rpx;
						font-size: 28rpx;
						color: #202020;

						&.on {
							color: #2f59fe;
							background: #edf4fd;
							border-color: #2f59fe;
						}
					}
				}
			}
		}

		.DiaLogShaix {
			display: flex;
			align-items: center;
			justify-content: center;
			text-align: center;
			height: 160rpx;

			.DiaLogShaiReset {
				display: inline;
				width: 280rpx;
				height: 80rpx;
				line-height: 78rpx;
				font-size: 32rpx;
				color: #202020;
				border: 1rpx solid #cfd2d7;
				box-sizing: border-box;
				margin: 0 10rpx;
				border-radius: 10rpx;
			}

			.DiaLogShaiSubmit {
				display: inline;
				width: 280rpx;
				height: 80rpx;
				line-height: 80rpx;
				font-size: 32rpx;
				color: #ffffff;
				background: #2f59fe;
				margin: 0 10rpx;
				border-radius: 10rpx;
			}
		}
	}
</style>